import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { ExAttributePanel } from "../deploy/ExAttributePanel";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { BatchRefreshData } from "../data/BatchRefreshData";
import { EffectManager } from "../../../manager/EffectManager";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { LineBox } from "../../guide/LineBox";
//class EquipBatchRefreshRender
    
    export  class EquipBatchRefreshRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initUI();
            return;
        }

        /* internal  */initUI(): void
        {
            ObjCreate.createLabel(Language.getString(60287), 0, 10, 145, 20, flash.text.TextFormatAlign.CENTER, this, true, 16776960).drawNow();
            this._exPanel = new ExAttributePanel();
            this._exPanel.x = 5;
            this._exPanel.y = 0;
            this._exPanel.type = ExAttributePanel.NewAttri;
            this._exPanel.showBg = false;
            this._exPanel.showLock = false;
            this.addChild(this._exPanel);
            this._replaceBtn = ObjCreate.createGButton(Language.getString(60233), 45, 152, 52, 22, this);
            this._replaceBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onReplaceBtnClick);
            this._replaceBtn.drawNow();
            return;
        }

        /* internal  */onReplaceBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (data) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Equipment_ReplaceBatchRefresh, data));
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            var loc1=data as BatchRefreshData;
            if (loc1) 
            {
                this._exPanel.setAttributesByAttrubutes(loc1.attributes, loc1.equipData);
                if (this.isGetExpectedAttribute()) 
                {
                    this.glowEffect(true);
                    loc1.hasExpectAttr = true;
                }
                else 
                {
                    this.glowEffect(false);
                    loc1.hasExpectAttr = false;
                }
            }
            else 
            {
                this.glowEffect(false);
            }
            return;
        }

        /* internal  */isGetExpectedAttribute(): Boolean
        {
            var loc3=null;
            var loc4=0;
            var loc1=data as BatchRefreshData;
            var loc2=loc1.equipData.itemExInfo.ref_lock.split(",");
            var loc5=(loc2.length - 1);
            while (loc5 < loc1.attributes.length) 
            {
                loc3 = loc1.attributes[loc5] as Array<any>;
                loc4 = loc3[0];
                if (loc1.expectAttr[loc4] != null) 
                {
                    if (loc3[1] >= loc1.expectAttr[loc4]) 
                    {
                        return true;
                    }
                }
                if (loc1.expectAttrAll > 0 && loc3[1] >= loc1.expectAttrAll) 
                {
                    return true;
                }
                ++loc5;
            }
            return false;
        }

        /* internal  */glowEffect(arg1: Boolean=true): void
        {
            if (arg1) 
            {
                if (!this._lineBox) 
                {
                    this._lineBox = EffectManager.getLineBox(this.width, this.height, null, 0.5, 2);
                    addChild(this._lineBox);
                }
                this._lineBox.x = 0;
                this._lineBox.y = 0;
            }
            else if (this._lineBox) 
            {
                EffectManager.disposeLineBox(this._lineBox);
                this._lineBox = null;
            }
            return;
        }

        public /* override */ get width(): number
        {
            return 145;
        }

        public /* override */ get height(): number
        {
            return 182;
        }

        /* internal */ /* var */_exPanel: ExAttributePanel;

        /* internal */ /* var */_replaceBtn: GButton;

        /* internal */ /* var */_lineBox: LineBox;
    }
